valid = "([{}])"
invalid1 = "{[})"
invalid2 = "{[)"


def valid_parentheses(input):
    p_map = {'{': '}', '(': ')', '[': ']'}
    stack = []
    for c in input:
        if c in p_map:
            stack.append(c)
        else:
            if not stack: return False
            l = stack.pop()
            if p_map[l] != c: return False

    if not stack: return True


print(valid_parentheses(valid))
print(valid_parentheses(invalid1))
print(valid_parentheses(invalid2))
